package oceanlife;

import java.awt.Container;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTextField;

import oceanlife.pathfinding.Pnt;

public class AgentCustomSettings {
	int xOffset = 0;
	int yOffset = 0;
	int interSpacing = 0;
	int itteration = 0;
	
	private Container contentPane;

	JCheckBox box = new JCheckBox();
	JLabel lab1 = new JLabel("x");
	JLabel lab2 = new JLabel("y");

	JTextField agx1 = new JTextField();
	JTextField agy1 = new JTextField();
	JTextField agx2 = new JTextField();
	JTextField agy2 = new JTextField();

	JTextField agNum = new JTextField();

	JTextField agGoalx = new JTextField();
	JTextField agGoaly = new JTextField();
	public AgentCustomSettings(Container cp){
		contentPane = cp;
		
		cp.add(box);
		cp.add(lab1);
		cp.add(lab2);
		cp.add(agx1);
		cp.add(agx2);
		cp.add(agy1);
		cp.add(agy2);
		cp.add(agNum);
		cp.add(agGoalx);
		cp.add(agGoaly);

	}

	public void setDimensions(int i, int xOffset, int yOffset, int interSpacing) {
		this.xOffset = xOffset;
		this.yOffset = yOffset;
		this.interSpacing = interSpacing;
		this.itteration = i;	

		box.setBounds(xOffset, yOffset+10+itteration*interSpacing, 18, 15);
		lab1.setBounds(xOffset+24, yOffset+2+itteration*interSpacing, 10, 15);
		lab2.setBounds(xOffset+24, yOffset+22+itteration*interSpacing, 10, 15);
		
		agx1.setBounds(xOffset+35, yOffset+itteration*interSpacing, 40, 18);
		agy1.setBounds(xOffset+35, yOffset+20+itteration*interSpacing, 40, 18);
		agx2.setBounds(xOffset+78, yOffset+itteration*interSpacing, 40, 18);
		agy2.setBounds(xOffset+78, yOffset+20+itteration*interSpacing, 40, 18);
		
		agNum.setBounds(xOffset+128, yOffset+10+itteration*interSpacing, 40, 18);

		agGoalx.setBounds(xOffset+178, yOffset+itteration*interSpacing, 40, 18);
		agGoaly.setBounds(xOffset+178, yOffset+20+itteration*interSpacing, 40, 18);
	}
	
	public boolean inUse(){
		return box.isSelected();
	}
	
	public Pnt getGoal(){
		return new Pnt(Double.parseDouble(agGoalx.getText()),Double.parseDouble(agGoaly.getText()));
	}
	
	public Pnt[] getSpawnBox(){
		Pnt p1 = new Pnt(Math.min(Double.parseDouble(agx1.getText()),Double.parseDouble(agx2.getText())),Math.min(Double.parseDouble(agy1.getText()),Double.parseDouble(agy2.getText())));
		Pnt p2 = new Pnt(Math.max(Double.parseDouble(agx1.getText()),Double.parseDouble(agx2.getText())),Math.max(Double.parseDouble(agy1.getText()),Double.parseDouble(agy2.getText())));
		return new Pnt[]{p1,p2};
	}

	public int getNumAgents(){
		return Integer.parseInt(agNum.getText());
	}

	public void setValues(boolean b, String i, String j, String k, String l, String m, String n, String o) {
		box.setSelected(b);
		agx1.setText(i);
		agy1.setText(j);
		agx2.setText(k);
		agy2.setText(l);
		agNum.setText(m);
		agGoalx.setText(n);
		agGoaly.setText(o);
	}
}
